<!doctype html>
<html>
<head>
    <meta charset="UTF-8">
    <title>用户管理</title><!--[if lt IE 9]>

    <![endif]-->


</head>
<body>
<section>
    <div>
        <div class="layui-card">
            <div class="layui-card-body">
                <div>
                    <button adp_btn method="addEntity"><i class="layui-icon layui-icon-add-circle-fine"></i>增加</button>
                    <button adp_btn method="deleteAllEntity"><i class="layui-icon layui-icon-close"></i>删除</button>
                </div>
            </div>
        </div>
        <div class="layui-card">
            <div class="adp-content">
                <form id="queryForm"></form>
                <table id="queryTable"></table>
            </div>
        </div>
    </div>
</section>
<div style="width: 600px;display: none;" id="mergeFormDiv">
    <form action="" method="post" id="mergeForm" class="adp-center"></form>
</div>
</body>
</html>
<script src="../static/adp/import.js"></script>

<script type="text/html" id="OPERATION_ROW_TPL">
    {{#  if(d.name!= 'admin'){ }}
    <a class="layui-btn layui-btn-sm" lay-event="edit"> <i class="layui-icon layui-icon-edit"></i>编辑</a>
    <a class="layui-btn layui-btn-danger layui-btn-sm" lay-event="del"><i class="layui-icon layui-icon-delete"></i>删除</a>
    {{#  } }}
</script>
<script type="text/html" id="USER_ROLE_TPL">
    {{# layui.each(d.roles, function(index, item){ }}
    <span class="layui-badge layui-bg-blue">{{= item.roleName}}</span>
    {{# }); }}
</script>

<script>
    var resources = SV("Resource")("getAllPrincipal")();
    var queryForm = $("#queryForm").adpForm({
        elem: [{
            type: "text",
            label: "角色名称",
            name: "roleName",
            placeholder: "请输入角色名称"
        }],
        button: [{
            type: "submit",
            label: "查询",
            method: "query"
        }, {
            type: "reset",
            label: "重置"
        }],
        methods: {
            query: function query() {
                queryTable.reload(this.data());
            }
        }
    });
    var mergeForm = $("#mergeForm").adpForm({
        layout: 'vertical',
        elem: [{
            type: "text",
            label: "名称",
            verify: "required",
            name: "roleName",
            placeholder: "请输入角色名称"
        }, {
            type: "checkbox",
            label: "权限",
            verify: "resources",
            data: [{

                name: "resources",
                value: 2,
                label: "demo"
            }]

        }, {
            type: "radio",
            label: "角色类型",
            data: [{
                name: "roleType",
                value: "admin",
                label: "超级管理员"
            }, {
                name: "roleType",
                value: "user",
                label: "普通角色",
                checked: true
            }]
        }, {
            type: "textarea",
            label: "描述",
            name: "describing",
            placeholder: "请输入描述"
        }, {
            type: "hidden",
            name: "id"
        }],
        button: [{
            type: "submit",
            label: "保存",
            method: "submit"
        }, {
            type: "reset",
            label: "重置"
        }],
        verify: {
            resources: function resources() {
                return "请选择权限";
            }
        },
        methods: {
            submit: function submit(data) {
                // SV("Role")("merge")(data);
                // $("#mergeFormDiv").close();
                queryTable.reload(queryForm.data());
            }
        }
    });
    var queryTable = $("#queryTable").adpTable({
        url: '../rs/Role/list',
        where: queryForm.data(),
        cols: [[{
            field: 'id',
            title: 'ID',
            type: 'checkbox',
            width: 30,
            sort: true,
            fixed: 'left'
        }, {
            field: 'roleName',
            title: '名称',
            width: 150
        }, {
            templet: function templet(_ref) {
                var roleType = _ref.roleType;
                return roleType == "admin" ? "超级管理员" : "普通角色";
            },
            title: '类型',
            width: 100
        }, {
            field: 'describing',
            title: '描述',
            width: 300
        }, {
            title: '权限',
            templet: function templet(_ref2) {

                return "xxx";
            }
        }, {
            fixed: 'right',
            title: '操作',
            width: 180,
            align: 'center',
            toolbar: '#OPERATION_ROW_TPL'
        }]],
        methods: {
            edit: function edit(data, tr) {
                if (data.roleName == "超级管理员") {
                    layer.msg("超级管理员不能编辑");
                    return;
                }

                $("#mergeFormDiv").open("编辑角色");
            },
            del: function del(data, tr) {


                layer.confirm('真的删除行么', function (index) {

                });
            }
        }
    });

    function addEntity() {
        return $("#mergeFormDiv").open("创建角色", {
            success: function success() {
                return mergeForm.reset();
            }
        });
    };

    function deleteAllEntity() {
        var _queryTable$checkStat = queryTable.checkStatus(),
            data = _queryTable$checkStat.data;

        layer.confirm('真的删除行么', function (index) {
            Deferred("Role")("xxxx")({
                ids: ids
            }).then(function () {
                queryTable.reload(queryForm.data());
                layer.close(index);
            });
        });
    };
</script>